import request from '@/utils/request'

// 创建OTA任务
export function createOTA(data) {
  return request({
    url: '/ota_task/create',
    method: 'post',
    data: data
  })
}

// 获取OTA任务列表
export function getOtaTaskList(query) {
  return request({
    url: `/ota_task/list`,
    method: 'get',
    params: query
  })
}
// 用户根据OTA任务id获取详情
export function getOtaTaskById(id) {
  return request({
    url: `/ota_task/${id}`,
    method: 'get',
  })
}
// 用户根据OTA任务id删除
export function deleteOtaTaskById(id) {
  return request({
    url: `/ota_task/delete/${id}`,
    method: 'delete'
  })
}

// 获取OTA任务历史列表
// export function getOtaActionLogList(query) {
//   return request({
//     url: `/ota_action_log/list`,
//     method: 'get',
//     params: query
//   })
// }

export function getOtaActionLogList(query) {
  return request({
    url: `/action_log_ota/list`,
    method: 'get',
    params: query
  })
}

// 创建OTA任务
export function mqttOtaUpgrade(data) {
  console.log('mqttOtaUpgrade',data)
  return request({
    url: '/mqtt/ota',
    method: 'post',
    data: data
  })
}

export function otaLogDetail(query) {
  console.log('mqttOtaUpgrade',query)
  return request({
    url: '/action_log_ota/list_gw_wb',
    method: 'get',
    params: query
  })
}
// 用户获取固件列表按固件类型分配好
export function getFirmwaresListByType() {
  return request({
    url: '/firmware/list_type',
    method: 'get',
  })
}
// 用户获取固件列表按固件类型分配好
export function getGatewayUpgradeStats() {
  return request({
    url: '/action_log_ota/getGatewayUpgradeStats',
    method: 'get',
  })
}

export function getFirmwareProdTask() {
  return request({
    url: '/firmware/productTask',
    method: 'get',
  })
}

export function SetFirmwareProdTask(data) {
  return request({
    url: '/firmware/productTask',
    method: 'post',
    data: data
  })
}

export function getTaskById(taskId) {
  return request({
    url: `/action_log_ota/getByTaskId/${taskId}`,
    method: 'get',
  })
}